package com.neuedu.my12306.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.neuedu.my12306.entity.UserInfo;
import com.neuedu.my12306.service.IUserInfoService;
import com.neuedu.my12306.service.impl.IUserInfoServiceImpl;

/**
 * Servlet implementation class ToUserInfoServlet
 */
@WebServlet("/ToUserInfoServlet.do")
public class ToUserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private IUserInfoService userInfoService;
    public ToUserInfoServlet() {
        super();
        userInfoService = new IUserInfoServiceImpl();
       
    }
	

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//Cookie[] cookies = req.getCookies();
		HttpSession session = req.getSession();
		String userName = session.getAttribute("LOGIN_USER").toString();
		//String userName=(String)req.getAttribute("LOGIN_USER");
		if (userName!=null) {
			UserInfo userInfo = userInfoService.findUserInfoByid(userName);
			req.setAttribute("userInfo", userInfo);
			req.getRequestDispatcher("/User/UserManageInfo.jsp").forward(req, resp);
			//System.out.println(userName);
		}else {
			resp.sendRedirect(req.getContextPath()+"/User/UserManageInfo.jsp");
			//System.out.println(userName);
		}
		
		
	}



}
